<template>
    <transition name="fade">
        <div v-if="visible" class="drawer-overlay" @click.self="close">
            <div class="drawer" :class="position">
                <button class="close-button" @click="close">×</button>
                <slot></slot>
            </div>
        </div>
    </transition>
</template>

<script setup>
// import { defineProps, defineEmits } from 'vue';

const props = defineProps({
    visible: {
        type: Boolean,
        default: false,
    },
    position: {
        type: String,
        default: 'right', // 可以是 'left' 或 'right'
    },
});

const emit = defineEmits();

const close = () => {
    emit('update:visible', false);
};
</script>


<style scoped>
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    z-index: 1000;
}

.drawer {
    background: var(--link-drawer-bg-color);
    width: 400px;
    height: 100%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--link-label-color);
}

.drawer.left {
    transform: translateX(-100%);
}

.drawer.right {
    transform: translateX(0);
}

.fade-enter-active,
.fade-leave-active {
    transition: opacity 0.3s;
}

.fade-enter,
.fade-leave-to {
    opacity: 0;
}

.close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #27ba9b;
}
</style>